<template>
	<view class="post" :class="[isDark?'dark':'', AppStyle]" :style="{'background-color':isDark?'#1c1c1c':'#f6f6f6','max-height':isDark?'100vh':'auto'}">
		<view class="header" :style="[{height:CustomBar + 'px'}]" v-if="showContent">
			<view class="cu-bar" :class="isDark?'dark':'bg-white'" :style="{'height': CustomBar + 'px','padding-top':StatusBar + 'px','background-color':isDark?'#1c1c1c':'#ffffff'}">
				<view class="action" @tap="isback">
					<text class="cuIcon-back"></text>
				</view>
				<view class="content text-bold" :style="[{top:StatusBar + 'px'}]">
					<block v-if="type=='edit'">
						{{$t('edit.articlepost.editarticle')}}
					</block>
					<block v-else>
						{{$t('global.publisharticle')}}
					</block>
				</view>
				<!--  #ifdef H5 || APP-PLUS -->
				<view class="action" @click="toDraft()" style="display: flex;color: #333;">
					<!-- <text class="cuIcon-upload"></text> -->
					<block v-if="type=='add'">
						<text style="margin-right: 5px;">{{$t('global.drafts')}}</text>
						<span class="tn-icon-edit-form" style="font-size: 40upx;"></span>
					</block>
				</view>
				<!--  #endif -->
			</view>
		</view>
		<view :style="[{padding:(NavBar+10) + 'px 10px 0px 10px'}]"></view>
		<form>
			<view class="cu-form-group margin-sm" :class="isDark?'dark':'bg-white'" :style="'border-radius: 20upx;background-color:'+(isDark?'#1c1c1c':'#ffffff')">
				<input placeholder="$t('edit.articlepost.plsarticletitle')" name="input" v-model="title" @focus="ToisText(0)" @blur="ToisText(0)" :adjust-position="false" :focus="false"/>
				<view class="picker" @tap="toCategory">
					<block v-if="categoryText==''">
						{{$t('global.selectcategory')}}
					</block>
					<block v-else>
						<text class="text-shojo">{{categoryText}}</text>
					</block>
				</view>
			</view>
			<view class="margin-sm" :class="isDark?'dark':'bg-white'" :style="'border-radius: 20upx;background-color:'+(isDark?'#1c1c1c':'#ffffff')">
				<view class="margin-sm">
					<cu-editor ref="editor" :mrPoster="videoPoster" :SPimg="SPimg" :musicpic='musicpic'
						editorId='editor' :NavBar="NavBar" @editorFocus="handleEditorFocus"
						@editorBlur="handleEditorBlur" :url="this.$API.upload()" :formData="formData" :content="text"
						:MusicUpload='MusicUpload' :uploadTime="uploadTime" :isPay="false" :isWz="true"
						@custom-event="setShop" @save="onSave"></cu-editor>
				</view>
			</view>
			<view class="margin-sm" :class="isDark?'dark':'bg-white'" :style="'border-radius: 20upx; padding: 14px;background-color:'+(isDark?'#1c1c1c':'#ffffff')+';'+(showContent?'':'display:none')">
				<view class="flex flex-row justify-between items-center" style="align-items: center;"
					@click="tagsShow=true">
					<text>{{$t('edit.articlepost.selectlabel')}}</text>
					<text>
						<block v-if="curTag.length==0">
							{{$t('common.select')}}
						</block>
						<block v-else>
							{{$t('common.selected')}}
						</block>
					</text>
				</view>
				<view class="margin-top-sm modal-concent" v-if="curTag.length!=0">
					<view class="tag-list">
						<view class="tag-box-2" v-for="(item,index) in curTag">
							#{{item.name}}
						</view>
					</view>
				</view>
			</view>
			<view :style="showContent?'':'display:none'">
				<!--#ifdef APP-PLUS || H5 -->
				<view v-if="type=='add'" class="margin-sm" style="display: flex;justify-content: space-between;">
					<tn-button type="button" :backgroundColor="isDark?'#2c2c2c':'#fff'" fontColor="#333" width="35%" class="form-btn"
						@click="submit(false)">{{$t('edit.articlepost.savedrafts')}}</tn-button>
					<tn-button type="button" :backgroundColor="isDark?'#2c2c2c':'#01BEFF'" fontColor="#fff" width="60%"
						class="form-btn" @click="submit(true)">{{$t('global.publisharticle')}}</tn-button>
				</view>
				<!--#endif -->
				<!--#ifdef MP-WEIXIN -->
				<view v-if="type=='add'" class="margin-sm">
					<tn-button type="button" :backgroundColor="isDark?'#2c2c2c':'#fff'" class="form-btn" fontColor="#333" width="100%"
						@click="submit(false)">{{$t('edit.articlepost.savedrafts')}}</tn-button>
					<view class="margin-top-sm">
						<tn-button type="button" :backgroundColor="isDark?'#2c2c2c':'#01BEFF'" fontColor="#fff" width="100%"
							class="form-btn margin-top-sm" @click="submit(true)">{{$t('global.publisharticle')}}</tn-button>
					</view>
				</view>
				<!--#endif -->

				<view v-else class="margin-sm">
					<tn-button type="button" :backgroundColor="isDark?'#2c2c2c':'#01BEFF'" fontColor="#fff" width="100%"
						class="form-btn" @click="submit(true)">
						<block v-if="draft==0">
							{{$t('edit.articlepost.editarticle')}}
						</block>
						<block v-if="draft==1">
							{{$t('global.publisharticle')}}
						</block>
					</tn-button>
				</view>
				<!--  #ifdef MP-WEIXIN -->
				<view class="margin-sm">
					<tn-button type="button" fontColor="#333" width="100%" class="form-btn" @click="toDraft()">
						<text style="margin-right: 5px;">{{$t('global.drafts')}}</text>
						<span class="tn-icon-edit-form" style="font-size: 30upx;"></span>
					</tn-button>
				</view>
				<!--  #endif -->


			</view>
		</form>
		<view class="setShop" v-if="isShop==1">
			<view class="setShop-box">
				<view class="setShop-main" style="box-shadow: 0px 4upx 40upx #d4d4d4;border-radius: 20upx;">
					<view class="setShop-title">
						{{$t('edit.articlepost.selproductarticle')}}
						<text class="setShop-close cuIcon-close" style="right: 0px;top: 0px;" @tap="isShop=0"></text>
					</view>
					<scroll-view class="setShop-list" scroll-y>
						<view class="setShop-list-box" v-for="(item,index) in shopList" @tap="toShop(item.id)"
							:class="item.id==shopID?'cur':''" :key="index">
							<view class="setShop-list-main">
								<text class="cuIcon-moneybagfill text-red"></text>{{item.title}}
							</view>
							<view class="setShop-status">
								<text v-if="item.cid!=-1">{{$t('edit.articlepost.cid')}}:{{item.cid}}</text>
								<text v-else class="text-green">{{$t('edit.articlepost.noinsert')}}</text>
							</view>
						</view>
					</scroll-view>
				</view>
			</view>
		</view>
		<div class="modal hasSearch" :class="tagsShow?'show':''">
			<div class="modal-bg" @click="tagsShow=false">
			</div>
			<div class="modal-main">
				<div class="modal-title" :style="isDark?'color: #c7cddb;':'color: #333;'">
					{{$t('edit.articlepost.selectlabel')}}
					<a href="javascript:;" @click="tagsShow=false">{{$t('edit.articlepost.close')}}</a>
				</div>
				<div class="modal-search">
					<input placeholder="$t('edit.articlepost.plskeyword')" type="text" v-model="tagsText" @input="searchTags()" />
					<button type="button"><i class="tn-icon-search"></i></button>
				</div>
				<div class="modal-concent">
					<div class="tag-list">
						<div class="tag-box" v-for="(item,index) in tagList" :class="item.active==1?'action':''"
							@click="toTagContents(item.name,item.mid,index)">
							#{{item.name}}
						</div>
					</div>
				</div>
			</div>
		</div>
		<view class="dark-bg" style="height: 500rpx;background: #1c1c1c;" v-if="isDark"></view>
	</view>
</template>

<script>
	import cuEditor from '@/components/cu-editor/cu-editor'
	import mpHtml from '@/components/mp-html/mp-html'
	import {
		localStorage
	} from '../../js_sdk/mp-storage/mp-storage/index.js'
	import darkModeMixin from '@/utils/darkModeMixin.js'
	// #ifdef APP-PLUS
	import owo from '../../static/app-plus/owo/OwO.js'
	// #endif
	// #ifdef H5
	import owo from '../../static/h5/owo/OwO.js'
	// #endif
	// #ifdef MP
	var owo = [];
	// #endif
	export default {
		mixins: [darkModeMixin],
		components: {
			cuEditor
		},
		data() {
			return {
				modelVisible: true,
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar,
				NavBar: this.StatusBar + this.CustomBar,
				AppStyle: this.$store.state.AppStyle,
				tempFiles: '',
				pageScrollTop: 0,
				modalName: "",
				contentEdit: '',
				token: "",
				isShow: false,
				curHeight: 0,
				jpHeight: 0,
				tagsShow: false,
				screenHeight: 0,
				postheight: 0,
				poststyle: "",
				readstyle: "",
				draft: 0,

				uploadTime: this.$API.getuploadTime(),
				isText: 0,
				//文章表单部分
				title: "",
				category: "",
				tag: "",
				categoryText: "",
				text: '',
				content: "",
				name: "",
				textRead: "",
				link: {
					title: "",
					url: "",
				},
				MusicUpload: this.$API.SPstarMusicUpload(),
				musicpic: this.$API.SPmusicpic(),
				videoPoster: this.$API.getVideoPoster(),
				SPimg: this.$API.SPimgs(),

				shopList: [],
				isShop: 0,
				shopID: -1,
				//页面状态
				type: "add",
				cid: 0,
				showContent: true,
				isOwO: false,
				owo: owo,
				owoList: [],
				OwOtype: "paopao",
				tagList: [],
				curNum: 0,
				curTagNum: 0,
				curTag: [],
				postlinktype: 0,
				tagsText: "",
				start: -1,
				tagYes: false,
				isLoading: false,
				toImg: false,
				isSpace: false,
				formData: {},

			}
		},
		onPullDownRefresh() {

		},
		onShow() {
			var that = this;
			// #ifdef APP-PLUS
			plus.navigator.setStatusBarStyle("dark")
			// #endif
			if (localStorage.getItem('userinfo')) {
				var userInfo = JSON.parse(localStorage.getItem('userinfo'));
				that.token = userInfo.token;
				if (userInfo.screenName) {
					that.name = userInfo.screenName;
				} else {
					that.name = userInfo.name;
				}
				that.formData = {
					'token': userInfo.token,
					'username': that.name
				}
			}
			if (localStorage.getItem('clist')) {
				that.categoryText = that.$t('common.selected');
				that.category = localStorage.getItem('clist');
			}
			if (localStorage.getItem('ctag')) {
				that.tag = localStorage.getItem('ctag');
			}
			if (localStorage.getItem('serImage')) {
				that.modalName = null;
				var serImage = localStorage.getItem('serImage');
				var h = "";
				if (that.text != "") {
					h = "\n";
				}
				var text = h + "!"+ that.$t('global.imagename') +"(" + serImage + ")";
				that.insetText(text);
				localStorage.removeItem('serImage');
			}
			that.getTaglist();
			// #ifdef APP-PLUS || H5
			that.owoList = that.owo.data.paopao.container;
			// #endif
		},
		onHide() {
			
		},
		onPageScroll(e) {
			this.pageScrollTop = e.scrollTop
		},
		onLoad(res) {
			var that = this;
			const modelViewTime = uni.getStorageSync('modelView');
			localStorage.setItem('isSaveWz', "false");
			if (modelViewTime) {
				const nowDate = +new Date();
				const isVisible = nowDate - modelViewTime > 1000 * 60 * 60 * 24;
				if (!isVisible) {
					this.modelVisible = false;
				}
			}
			// #ifdef APP-PLUS || MP
			that.NavBar = that.CustomBar;
			// #endif
			if (res.type) {
				that.type = res.type;
				if (res.cid) {
					that.cid = res.cid;
					that.setloading();
					var timer = setTimeout(function() {
						that.getInfo(that.cid);
					}, 500)
				}
			}
			if (res.draft) {
				that.draft = res.draft;
			}
			if (res.isSpace) {
				if (res.isSpace == 1) {
					that.isSpace = true;
				}
			}
			that.getShopList();
			//键盘弹出相关
			let screenHeight = uni.getSystemInfoSync().screenHeight;
			let statusHeight = uni.getSystemInfoSync().statusBarHeight;
			let inputHeight = screenHeight - statusHeight - 290;
			// #ifdef APP-PLUS
			inputHeight = screenHeight - statusHeight - 300;
			// #endif
			// #ifdef H5
			inputHeight = 400;
			// #endif
			that.screenHeight = screenHeight - that.NavBar;
			that.postheight = inputHeight;
			//
			//that.poststyle = "height:200upx";
			that.poststyle = "height:" + inputHeight + "px";
			that.readstyle = "height:" + (inputHeight + 30) + "px;white-space: pre-wrap;";
			// #ifdef H5
			//that.h5Keyboard();
			// #endif
			uni.onKeyboardHeightChange(res => {
				//监听软键盘的高度 
				//当点击软键盘自带的收起按钮的时候也就是会隐藏软键盘 这时候监听到的软键盘的高度就是0 、
				//让输入框取消焦点 这时候再去输入内容的时候 输入框就会弹起
				if (res.height == 0) {
					that.focalize(res.height);
					that.poststyle = "height:" + inputHeight + "px";
				} else {
					that.curHeight = res.height;
					var keyHeight = inputHeight - res.height;
					that.focus(res.height);
					that.poststyle = "height:" + keyHeight + "px";
				}
			});
			localStorage.removeItem('clist')
		},
		methods: {
			okBtn() {
				const nowDate = +new Date();
				uni.setStorageSync('modelView', nowDate);
				this.cancleBtn();
			},
			handleEditorFocus() {
				this.showContent = false;
				this.NavBar = this.StatusBar;
			},
			handleEditorBlur() {
				this.showContent = true;
				this.NavBar = that.CustomBar;
			},
			cancleBtn() {
				this.modelVisible = false;
			},
			onSave(e) {
				var that = this
				that.content = e.html;
			},
			toSpace(e) {
				this.isSpace = e.detail.value
			},
			setloading() {
				var that = this;
				if (!that.isLoading) {
					uni.showLoading({
						title: that.$t('global.obtaindata'),
					});
				} else {
					uni.hideLoading();
				}
			},
			markHtml(text) {
				var that = this;
				text = that.replaceAll(text, "@!!!", "@@@@");
				text = that.replaceAll(text, "!!!", "");
				text = that.replaceAll(text, "@@@@", "@!!!");
				var owoList = that.owoList;
				for (var i in owoList) {
					if (text.indexOf(owoList[i].data) != -1) {
						text = that.replaceAll(that.replaceSpecialChar(text), owoList[i].data, "<img src='" + owoList[i].icon + "' class='tImg' />")
					}
				}
				//text = text.replace(/(?<!\r)\n(?!\r)/g, "\n\n");
				//兼容垃圾的Safari浏览器
				text = text.replace(/([^\r])\n([^\r])/g, "$1\n\n$2");
				text = that.replaceAll(text, "||rn||", "\n\n");
				return text;
			},
			replaceSpecialChar(text) {
				if (!text) {
					return false;
				}
				text = text.replace(/&quot;/g, '"');
				text = text.replace(/&amp;/g, '&');
				text = text.replace(/&lt;/g, '<');
				text = text.replace(/&gt;/g, '>');
				text = text.replace(/&nbsp;/g, ' ');
				return text;
			},
			replaceAll(string, search, replace) {
				return string.split(search).join(replace);
			},
			ToisText(i) {
				var that = this;
				that.isText = i;
				if (that.curHeight != 0 && that.isText == 1) {
					that.focus(that.curHeight);
				}
				uni.getSelectedTextRange({
					success: res => {
						that.start = res.start;
					}
				})
			},
			insetText(newStr) {
				var that = this;
				var start = that.start;
				var text = that.text;
				if (start == -1) {
					text += newStr;
				} else {
					text = text.slice(0, start) + newStr + text.slice(start);
				}
				that.text = text;
				that.textRead = that.text;
			},
			focus(h) {
				var that = this;
				if (that.isText == 0) {
					return false;
				}
				// #ifdef APP-PLUS
				// let screenHeight = uni.getSystemInfoSync().screenHeight;
				// let statusHeight= uni.getSystemInfoSync().statusBarHeight;
				// let inputHeight = screenHeight - statusHeight - 240;
				// that.screenHeight = screenHeight - statusHeight - 5;
				// let height = h;
				// let postheight = that.postheight - height;

				// that.jpHeight =height - statusHeight;


				// that.postheight = postheight;
				// that.poststyle = "height:"+postheight+"px";
				// that.readstyle = "height:"+(inputHeight+30)+"px";
				// #endif
			},
			focalize(h) {
				var that = this;
				// #ifdef APP-PLUS
				// let screenHeight = uni.getSystemInfoSync().screenHeight;
				// let statusHeight= uni.getSystemInfoSync().statusBarHeight;
				// that.screenHeight = screenHeight - that.NavBar;
				// let inputHeight = screenHeight - statusHeight - 250;
				// that.jpHeight =0;
				// that.postheight = inputHeight;
				// that.poststyle = "height:"+inputHeight+"px";
				// #endif
			},
			back() {
				localStorage.removeItem('clist');
				localStorage.removeItem('isSaveWz')
				uni.navigateBack({
					delta: 1
				});
			},
			PickerChange(e) {
				this.index = e.detail.value
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal() {
				this.modalName = null
			},
			textareaAInput() {
				var that = this;
				uni.getSelectedTextRange({
					success: res => {
						that.start = res.start;
					}
				})
				that.textRead = that.text;
			},
			//编辑器工具开始
			toBold() {
				var that = this;
				var h = "";
				var text = h + that.$t('global.boldtxt');
				that.insetText(text);
			},
			toHideText() {
				var that = this;
				var h = "";
				var text = h + "[hide]"+that.$t('edit.articlepost.replyvisibletxt')+"[/hide]";
				that.insetText(text);
			},
			toItalic() {
				var that = this;
				var h = "";
				var text = h + that.$t('global.italicizedtxt');
				that.insetText(text);
			},
			toTitle(num) {
				var that = this;
				var text = "";
				for (var i = 0; i < num; i++) {
					text = text + "#";
				}
				var h = "";
				if (that.text != "") {
					h = "\n";
				}
				var title = h + text + that.$t('global.titletxt');
				that.insetText(title);
				that.hideModal();
			},
			toDraft() {
				uni.navigateTo({
					url: '/pages/user/draftList'
				});
			},
			getTaglist() {
				var that = this;
				var params = {
					"type": "tag"
				}
				var data = {
					"searchParams": JSON.stringify(params),
					"limit": 100,
					"page": 1,
					"order": "order",
					"searchKey": that.tagsText,
				}
				that.$Net.request({
					url: that.$API.getMetasList(),
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					data: data,
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 1) {
							var tagList = res.data.data;
							for (var i in tagList) {
								tagList[i].active = 0;
							}
							that.tagList = tagList;
							that.tagYes = true;
						}
					},
					fail: function(res) {
						
					},
				})
			},
			searchTags() {
				var that = this;
				var tagList = that.tagList;
				for (var i in tagList) {
					tagList[i].active = 0;
				}
				that.tagList = tagList;
				that.getTaglist();
			},
			toIsShow(isTo) {
				var that = this;
				var group = "";
				if (localStorage.getItem('userinfo')) {

					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					var group = userInfo.group;
				}
				if (!isTo && !that.isShow) {
					if (group == 'administrator' || group == 'editor') {
						if (that.text.indexOf("<script>") != -1 || that.text.indexOf("<form>") != -1 || that.text.indexOf(
								"<iframe>") != -1 || that.text.indexOf("<frame>") != -1) {
							that.modalName = "xss"
							return false;
						}
					}
				}
				that.modalName = null;
				that.textRead = that.text;
				that.isShow = !that.isShow;
			},
			submit(isPost) {
				var that = this;
				var type = that.type;
				if (isPost) {
					if (type == "add") {
						that.$refs.editor.save()
						setTimeout(function() {
							that.contentsAdd(false);
						}, 200)
					} else {
						that.$refs.editor.save();
						setTimeout(function() {
							that.contentsUpdate();
						}, 200)
					}
				} else {
					if (type == "add") {
						that.$refs.editor.save()
						setTimeout(function() {
							that.contentsAdd(true);
						}, 200)
					}
				}
				// if(that.shopID!=-1){
				// 	that.mountShop();
				// }
			},
			toTagContents(title, id, index) {
				var that = this;
				if (that.tagList[index].active == 1) {
					that.curNum--;
					that.tagList[index].active = 0;
				} else {
					if (that.curNum > 4) {
						uni.showToast({
							title: that.$t('edit.articlepost.mostselfivelabel'),
							icon: 'none',
							duration: 2000
						});
						return false;
					}
					that.curNum++;
					that.tagList[index].active = 1;
				}
				var curTag = [];
				var tagList = that.tagList;
				for (var i in tagList) {
					if (tagList[i].active == 1) {
						curTag.push(tagList[i]);
					}
				}
				that.curTag = curTag;
			},
			isback() {
				var that = this;
				var isSave = localStorage.getItem('isSaveWz');
				if (isSave == 'true') {
					that.back()
				} else {
					uni.showModal({
						title: that.$t('global.prompt'),
						content: that.$t('global.editnosave'),
						cancelText: that.$t('global.exit'),
						confirmText: that.$t('global.leave'),
						success: function(res) {
							if (res.confirm) {

							} else if (res.cancel) {
								that.back()
							}
						}
					});
				}
			},
			contentsAdd(Draft) {
				var that = this;
				if (that.title == "") {
					uni.showToast({
						title: that.$t('global.titlenoempty'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.content == '<p><br></p>' || that.content == '') {
					uni.showToast({
						title: that.$t('global.contextnoempty'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.category == "") {
					uni.showToast({
						title: that.$t('global.plsselclassify'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				var isSpace = 0;
				var tag = "";
				if (that.curTag.length > 0) {
					var curTag = that.curTag;
					for (var i in curTag) {
						if (curTag[i].active == 1) {
							tag += "," + curTag[i].mid;
						}
					}
				}
				var isDraft = 0;
				if (Draft) {
					isDraft = 1
				}
				var data = {
					'title': that.title,
					'category': that.category,
					'tag': tag,
					'sid': that.shopID
				}
				var text = that.content;
				text = text.replace(/\r\n/g, "||rn||");
				text = text.replace(/\n/g, "||rn||");
				uni.showLoading({
					title: that.$t('common.loadmore')
				});
				that.$Net.request({
					url: that.$API.contentsAdd(),
					data: {
						"params": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"token": that.token,
						'text': text,
						"isDraft": isDraft,
						"isSpace": 0,
						'isMd': 0
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						if (res.data.code == 1) {
							if (!Draft) {
								// 设置刷新标记
								localStorage.setItem('needRefreshHome', 'true');
								localStorage.setItem('needRefreshFind', 'true');
								uni.showToast({
									title: res.data.msg,
									mask: false,
									icon: 'icon-success',
									duration: 3000
								})
								// 发布成功后后退1页
								var timer = setTimeout(function() {
									uni.navigateBack({
										delta: 1
									});
								}, 1000)
							} else {
								localStorage.setItem('isSaveWz', "true");
								uni.showToast({
									title: that.$t('edit.articlepost.alsavedrafts'),
									icon: 'none',
									duration: 2000
								})
							}
						} else {
							uni.showToast({
								title: res.data.msg,
								mask: false,
								icon: 'icon-error',
								duration: 3000
							})
						}
					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
						uni.stopPullDownRefresh()
					}
				})
			},
			contentsUpdate() {
				var that = this;
				if (that.title == "") {
					uni.showToast({
						title: that.$t('global.titlenoempty'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.content == '<p><br></p>' || that.content == '') {
					uni.showToast({
						title: that.$t('global.contextnoempty'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				if (that.category == "") {
					uni.showToast({
						title: that.$t('global.plsselclassify'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					return false
				}
				var tag = "";
				if (that.curTag.length > 0) {
					var curTag = that.curTag;
					for (var i in curTag) {
						if (curTag[i].active == 1) {
							tag += "," + curTag[i].mid;
						}
					}
				}
				var data = {
					'cid': that.cid,
					'title': that.title,
					'category': that.category,
					'tag': tag,
					'sid': that.shopID
				}
				uni.showLoading({
					title: that.$t('common.loadmore')
				});
				var text = that.content;
				text = text.replace(/\r\n/g, "||rn||");
				text = text.replace(/\n/g, "||rn||");
				that.$Net.request({
					url: that.$API.contentsUpdate(),
					data: {
						"params": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"token": that.token,
						'text': text,
						'isMd': 0,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "post",
					dataType: 'json',
					success: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						if (res.data.code == 1) {
							localStorage.removeItem('clist');
							localStorage.removeItem('ctag');
							var timer = setTimeout(function() {
								that.back();
							}, 1000)

						}
					},
					fail: function(res) {
						setTimeout(function() {
							uni.hideLoading();
						}, 1000);
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
						uni.stopPullDownRefresh()
					}
				})
			},
			getInfo(cid) {
				var that = this;
				if (!that.tagYes) {
					that.getInfo(cid)
					return false
				}
				var token = "";
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					token = userInfo.token;
				}
				var data = {
					"key": that.cid,
					"token": token,
				}
				that.$Net.request({
					url: that.$API.getContentsInfo(),
					data: data,
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.title) {
							that.title = res.data.title;
							if (res.data.category.length > 0) {
								that.categoryText = that.$t('common.selected');
								var list = res.data.category;
								var clist = "";
								for (var i in list) {
									clist += "," + list[i].mid;
								}
								localStorage.setItem('clist', clist);
								that.category = clist;
							}
							if (res.data.tag.length > 0) {
								var curTag = res.data.tag;
								for (var i in curTag) {
									var curMid = curTag[i].mid;
									for (var j in that.tagList) {
										if (that.tagList[j].mid === curMid) {
											that.tagList[j].active = 1;
											that.curNum++;
											break;
										}
									}
								}
								that.curTag = curTag
							}
							that.text = res.data.text;
							that.isLoading = true;
							that.setloading();
						}
					},
					fail: function(res) {
						
					}
				})
			},
			toMate(data) {
				var that = this;
				that.categoryText = data.name;
				that.category = data.mid,
					that.hideModal();
			},
			setShop() {
				var that = this;
				that.isShop = 1;
			},
			toShop(id) {
				var that = this;
				that.shopID = id;
				that.isShop = 0;
				uni.showToast({
					title: that.$t('edit.articlepost.alinstallproduct'),
					icon: 'none',
					duration: 1000,
					position: 'center',
				});
			},
			getShopList() {
				var that = this;
				var uid = 0;
				if (localStorage.getItem('userinfo')) {
					var userInfo = JSON.parse(localStorage.getItem('userinfo'));
					uid = userInfo.uid;
				} else {
					uni.showToast({
						title: that.$t('common.plslogin'),
						icon: 'none',
						duration: 1000,
						position: 'bottom',
					});
					var timer = setTimeout(function() {
						uni.navigateTo({
							url: '/pages/user/login'
						});
						clearTimeout('timer')
					}, 1000)
					return false
				}
				var data = {
					"uid": uid,
					"status": 1,
					"type": 1,
				}
				that.$Net.request({
					url: that.$API.shopList(),
					data: {
						"searchParams": JSON.stringify(that.$API.removeObjectEmptyKey(data)),
						"limit": 1000,
						"page": 1,
					},
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					method: "get",
					dataType: 'json',
					success: function(res) {
						if (res.data.code == 1) {
							var list = res.data.data;
							that.shopList = list;
							if (that.cid != 0) {
								for (var i in list) {
									if (list[i].cid == that.cid) {
										that.shopID = list[i].id;
									}
								}
							}
						}
					},
					fail: function(res) {
						uni.showToast({
							title: that.$t('common.networkfail'),
							icon: 'none'
						})
					}
				})
			},
			toOwO(text) {
				var that = this;
				that.OwOtype = text;
				if (text == "paopao") {
					that.owoList = that.owo.data.paopao.container;
				}
				if (text == "adai") {
					that.owoList = that.owo.data.adai.container;
				}
				if (text == "alu") {
					that.owoList = that.owo.data.alu.container;
				}
				if (text == "quyinniang") {
					that.owoList = that.owo.data.quyinniang.container;
				}
			},
			setOwO(data) {
				var that = this;
				var text = data.data;
				that.insetText(text);
				that.isOwO = false;
				that.textRead = that.markHtml(that.text);
			},
			OwO() {
				var that = this;
				that.isOwO = !that.isOwO;
			},
			toCategory() {
				uni.navigateTo({
					url: '/pages/contents/allcategory?type=edit'
				});
			},
			addTag() {
				uni.navigateTo({
					url: '/pages/contents/alltag?type=edit'
				});
			},
			toPostlinktype(i) {
				var that = this;
				that.postlinktype = i;
			},
			toAddShop() {
				uni.navigateTo({
					url: '/pages/edit/addshop'
				});
			},
			goImgData() {
				uni.navigateTo({
					url: '/pages/contents/imagetoday?type=post'
				});
			},
		}
	}
</script>

<style>
	a {
		text-decoration: none;
		outline: none;
		border: none;
		color: #3cc9a4;
	}

	.form-tag,
	.tag-list {
		width: 100%;
		overflow: hidden;
	}

	.form-tag .form-tag-box,
	.tag-list .tag-box {
		float: left;
		margin: 5px;
		height: 16px;
		padding: 5px 10px;
		color: #3cc9a4;
		border: solid 1px #3cc9a4;
		border-radius: 14px;
		font-size: 12px;
	}

	.tag-box-2 {
		float: left;
		margin: 5px;
		height: 28px;
		padding: 5px 10px;
		color: #3cc9a4;
		border: solid 1px #3cc9a4;
		border-radius: 14px;
		font-size: 12px;
	}

	.tag-list .tag-box.action {
		color: #fff;
		background-color: #3cc9a4;
	}

	.modal {
		width: 100%;
		height: 100vh;
		position: fixed;
		z-index: 10089;
		top: 0;
		left: 0;
		visibility: hidden;
		opacity: 0;
		transition: all 0.3s;
	}

	.modal.show {
		opacity: 1;
		visibility: initial;
	}

	.modal-bg {
		background: #000;
		opacity: 0.4;
		width: 100%;
		height: 100vh;
		left: 0;
		top: 0;
		position: fixed;
	}

	.modal-main {
		width: 100%;
		background: #fff;
		height: 250px;
		bottom: 0;
		position: fixed;
		box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.4);
		border-radius: 20px 20px 0px 0px;
		box-sizing: border-box;
		padding: 10px 20px;
	}

	.hasSearch .modal-main {
		height: 350px;
	}

	.categoryBox .modal-main {
		height: 400px;
	}

	.modal-title {
		font-weight: bold;
		height: 40px;
		line-height: 40px;
		font-size: 15px;
	}

	.modal-title a {
		float: right;
		font-weight: normal;
	}

	.modal-concent {
		height: calc(100% - 50px);
		width: 100%;
		overflow: auto;
	}

	.hasSearch .modal-concent {
		height: calc(100% - 85px);
	}

	.modal-search {
		width: 100%;
		overflow: hidden;
		height: 35px;
		box-sizing: border-box;
		border-bottom: solid 1px #f6f6f6;
	}

	.modal-search input {
		display: block;
		height: 35px;
		border: none;
		outline: none;
		width: calc(100% - 35px);
		float: left;
		box-sizing: border-box;
		padding: 0px 10px;
	}

	.modal-search button {
		border: none;
		display: block;
		height: 35px;
		outline: none;
		background: none;
		width: 35px;
		box-sizing: border-box;
		padding: 0px;
		text-align: center;
		color: #000;
		float: left;
	}

	.modal-title a.addShop {
		float: none;
		color: #f57070;
		margin-left: 5px;
	}
</style>